import java.util.Scanner;
public class POJ_1753 {
    static int min = 99999;
    static int step;
    static int flag;
    static char[][] a = new char[4][4];

    public static void main(String[] args) {
        POJ_1753 acm = new POJ_1753();
        String str;
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 4; i++) {
            str = sc.nextLine();
            for (int j = 0; j < 4; j++) {
                a[i][j] = str.charAt(j);
            }
        }
        step = 0;
        flag = 0;
        acm.dfs(0, 0, step);
        System.out.println(min);
    }

    char[][] change(int i, int j) {
        try {
            a[i][j] = a[i][j] == 'w' ? 'b' : 'w';
        } catch (Exception e){

        };
        try {
            a[i + 1][j] = a[i + 1][j] == 'w' ? 'b' : 'w';
        } catch (Exception e) {
        }
        try {
            a[i - 1][j] = a[i - 1][j] == 'w' ? 'b' : 'w';
        } catch (Exception e) {
        }
        try {
            a[i][j + 1] = a[i][j + 1] == 'w' ? 'b' : 'w';
        } catch (Exception e) {
        }
        try {
            a[i][j - 1] = a[i][j - 1] == 'w' ? 'b' : 'w';
        } catch (Exception e) {
        }
        return a;
    }

    boolean check() {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (a[0][0] != a[i][j])
                    return false;
            }
        }
        return true;
    }

    void dfs(int i, int j, int sp) {
        if (check()) {
            flag = 1;
            step = sp;
            if (step <= min) {
                min = step;
            }
            return;
        }
        if (i == 4 || j == 4)
            return;
        if (j < 3)
            dfs(i, j + 1, sp);
        else
            dfs(i + 1, 0, sp);
        change(i, j);
        if (j < 3)
            dfs(i, j + 1, sp + 1);
        else
            dfs(i + 1, 0, sp + 1);
        change(i, j);
    }
}
